#include<iostream>

using namespace std ;

const int maxn = 100010 ;
const int maxm = 100010 ;

//P是模式串，S是模板串
char P[maxn] , S[maxm] ;
int ne[maxn] ;

//求ne数组
void getNext(int length) {
    int i = 0;
    int j = -1;
    ne[0] = -1 ;
    while(i < length) {
        if (j == -1 || P[i] == P[j]) {
            i++;
            j++;
            ne[i] = j;
        } else {
            j = ne[j] ;
        }
    }
}

//KMP算法
int kmp(int length1 , int length2) {
    int i = 0 ;
    int j = 0 ;
    while(i <= length1 && j<= length2) {
        if(j == 0 || P[i] == S[j]) {
            i ++ ;
            j ++ ;
        } else {
            j = ne[j] ;
        }
    }
    if(j == length2) {
        return i - j ;
    } else
    {
        return -1;
    }
}

int main() {

    int length1 , length2 ;
    cin >> length1 ;
    cin >> P ;
    cin >> length2 ;
    cin >> S ;

    getNext(length1);

    printf("%d" , kmp(length1 , length2));

    return 0 ;
}